<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>加盟管理</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <jsp:include page="../com/header.jsp"></jsp:include>
    <script type="text/javascript" src="../../js/comm/listcomm.js"></script>
    <script type="text/javascript">
        var contentUrl = root + "/cms/franchiseTable/findFranchiseTableNEStatusPage";
        var checkurl = root + 'cms/franchiseTable/operateFranchiseStateTableByIds';
        var delArray = [];
        function getfilter() {
            var _jsonFilter = "{";
            if ($("#search_customer_Name").val() && $("#search_customer_Name").val().length > 0) {
                _jsonFilter += "'search_EQ_customer_Name':'" + $("#search_customer_Name").val().replace("'", "\"") + "',";
            }
            if ($("#search_cellphone").val() && $("#search_cellphone").val().length > 0) {
                _jsonFilter += "'search_LIKE_cellphone':'" + $("#search_cellphone").val().replace("'", "\"") + "',";
            }
            if ($("#search_franchise_Unit_Name").val() && $("#search_franchise_Unit_Name").val().length > 0) {
                _jsonFilter += "'search_EQ_franchise_Unit_Name':'" + $("#search_franchise_Unit_Name").val().replace("'", "\"") + "',";
            }
            if ($("#search_franchise_State").val() && $("#search_franchise_State").val().length > 0) {
                _jsonFilter += "'search_EQ_franchise_State':'" + $("#search_franchise_State").val().replace("'", "\"") + "',";
            }
            if (_jsonFilter != "{") {
                _jsonFilter = _jsonFilter.substring(0, _jsonFilter.length - 1);
            }
            _jsonFilter += "}";
            return _jsonFilter;
        }

        $(document).ready(function () {
            //同意审批审核
            $("#agreeSomeFranchise").click(function () {
                var checkError = false;
                var delArray = [];
                $(".ckSelect").each(function () {
                    var check = $(this).is(':checked');
                    if (check) {
                        var a = $(this).parents('tr').find('td:eq(5)').html();
                        if (a != "待审核") {
                            return;
                        }
                        var _id = $(this).attr("ckId");
                        delArray.push(_id);
                    }
                });
                if (delArray.length == 0) {
                    myAlert("请选择一条信息进行操作的项");
                    return;
                }
                if (delArray.length > 1) {
                    myAlert("每次只能审核一项");
                    return;
                }
                myConfirm("你确定要审核吗？", function () {
                    if (confirm("你确定要审核吗？")) {
                        $.ajax({
                            url: checkurl,
                            type: 'post',
                            data: {
                                modelIds: delArray.join(","),
                                franchise_State: 2,
                                refuse_Reason: null
                            },
                            dataType: 'json',
                            success: function (data) {
                                if (data.code == 1) {
                                    dipscontent(getfilter(), contentUrl);
                                    $("#_selectAll").attr("checked", false);
                                } else {
                                    myAlert(data.msg);
                                }
                            }
                        });
                    }
                });
            });

            //拒绝审批审核
            $("#refuseSomeFranchise").click(function () {
                var checkError = false;
                var cStatus = 3;
                delArray.splice(0, delArray.length);
                $(".ckSelect").each(function () {
                    var check = $(this).is(':checked');
                    if (check) {
                        var _franchise_State = $(this).attr("franchise_State");
                        if (_franchise_State != 1) {
                            myAlert('只有待审核的状态才能进行操作!');
                            return;
                        }
                        var _id = $(this).attr("ckId");
                        delArray.push(_id);
                    }
                });
                if (delArray.length == 0) {
                    return
                }
                if (delArray.length > 1) {
                    myAlert("每次只能审核一项!");
                    return;
                }
                $("refuseReason").val("");
                $("#franchiseModal").modal();
            });


            //拒绝确认按钮
            $("#confirmRejectBtn").click(function () {
                if ($("#refuseReason").val().length == 0) {
                    myAlert("请输入拒绝原因！");
                    return;
                }
                $.ajax({
                    url: checkurl,
                    type: 'post',
                    data: {
                        modelIds: delArray.join(","),
                        franchise_State: 3,
                        refuse_Reason: $("#refuseReason").val()
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1) {
                            dipscontent(getfilter(), contentUrl);
                            window.location.reload();
                            $('#franchiseModal').modal('hide');
                        } else {
                            myAlert(data.msg);
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>

<section>
    <div>
        <div class="col-xs-12">
            <div class="box">
                <form id="search_form" class="form-horizontal">
                    <div class="tabSelect" id="selectHeadId">
                        <br>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">姓名：</label>
                            <div class="col-md-8">
                                <input type="text" placeholder="姓名" class="form-control input-sm"
                                       id="search_customer_Name" name="customer_Name"/>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">手机号：</label>
                            <div class="col-md-8">
                                <input type="text" placeholder="手机号" class="form-control input-sm" id="search_cellphone"
                                       name="cellphone"/>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">公司名称：</label>
                            <div class="col-md-8">
                                <input type="text" placeholder="公司名称" class="form-control input-sm"
                                       id="search_franchise_Unit_Name" name="franchise_Unit_Name"/>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">状态：</label>
                            <div class="col-md-8">
                                <select class="form-control input-sm" id="search_franchise_State" name="type">
                                    <option value="">请选择</option>
                                    <option value="1">待审核</option>
                                    <option value="2">审核通过</option>
                                    <option value="3">审核拒绝</option>
                                </select>
                            </div>
                        </div>
                        <input type="button" value="查询" id="search" class="btn btn-primary searchBtn">
                    </div>
                </form>
                <div class="box-body table-responsive" style="clear:both;">
                    <input type="button" value="通过" id="agreeSomeFranchise" class="btn btn-success">
                    <input type="button" value="拒绝" id="refuseSomeFranchise" class="btn btn">
                </div>
                <div class="box-body table-responsive">
                    <table id="example2" class="table table-bordered">
                        <thead>
                        <tr>
                            <th width="20"><input type="checkbox" id="_selectAll"/></th>
                            <th width="40">申请人姓名</th>
                            <th width="40">手机号码</th>
                            <th width="80">公司名称</th>
                            <th width="80">照片</th>
                            <th width="40">状态</th>
                            <th width="40">申请的协议</th>
                            <th width="80">拒绝原因</th>
                        </tr>
                        </thead>
                        <!-- 表格内容 start -->
                        <tbody id="mycontent"></tbody>
                        <!-- 表格内容 end -->
                    </table>
                    <!-- 分页标签 start -->
                    <div class="row page_big_div" id="displayPage"></div>
                    <!-- 分页标签 end -->
                    <script id="tableContentTmple" type="text/x-jsrender">
								<tr>
									<td><input id="ck_{{:id}}" ckId="{{:id}}"  ckStatus="{{:status}}" franchise_State="{{:franchise_State}}" class="ckSelect" type="checkbox" /></td>
									<td>{{:customer_Name}}</td>
									<td>{{:cellphone}}</td>
									<td title={{:franchise_Unit_Name}} style="vertical-align:middle; text-align:left;">{{subStrings:franchise_Unit_Name lens=15}}</td>
									<td id="layer-photos-demo{{:id}}" class="layer-photos-demo">
                                        {{if franchise_Unit_PicUrls}}
                                            {{for franchise_Unit_PicUrls.split(",")}}
                                                <img layer-src="../../{{:}}" layer-pid="" src="../../{{:}}" alt="" layer-index="0" height="40" width="50">
                                            {{/for}}
                                        {{else}}
                                        {{/if}}
									</td>
									<td>{{if franchise_State==1}}待审核{{else franchise_State==2}}审核通过{{else franchise_State==3}}审核拒绝{{else}}无效{{/if}}</td>
									<td>
									    <div style="word-break: break-all;line-break: normal;">{{:agreementsStr}}</div>
									</td>
									<td title={{:refuse_Reason}}>{{subStrings:refuse_Reason lens=15}}</td>
								</tr>

                    </script>
                </div>
            </div>
        </div>
</section>

<!-- 审核拒绝弹出框 -->
<div class="modal fade" id="franchiseModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <form id="validateForm" class="form-horizontal">
        <div class="modal-dialog">
            <div class="modal-content" style="width:400px;margin-left:-100px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">审核信息</h4>
                </div>
                <div class="modal-body" id="detail_content">
                    <input type="text" placeholder="请输入审核信息" class="form-control input-sm" id="refuseReason"
                           name="refuseReason"/>
                </div>
                <center>
                    <div class="box-footer" style="background-color: #fff;width: 100px;padding-bottom: 20px;">
                        <input type="button" value="确定" id="confirmRejectBtn" class="btn btn-success;"
                               data-dismiss="modal" aria-hidden="true">
                    </div>
                </center>
            </div>
        </div>
    </form>
</div>

</body>
</html>